package com.yumingjiang.component.sentinel;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.yumingjiang.common.model.Result;
import com.yumingjiang.common.util.ResultUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @description:
 * @author: John
 * @version: SentinelBlockCallback.java, v1.0 2024年12月31日 21:55
 */

@Slf4j
public class SentinelBlockCallback {

    public static Result handleBlockException(HttpServletRequest request, @RequestParam("id") String id, BlockException ex) {
        // 处理异常逻辑，返回相应的结果
        log.error("限流处理 >> " + ex.getRule() + "-" + ex.getLocalizedMessage());

        return ResultUtil.buildError(request.getRequestURI() + "资源请求被限流");
    }
}